Link Search Menu Expand Document

Introduction

Finally, we will write the code and check if your bot is working.

Steps

Step 1. Return to PyCharm and write the same code as the picture below on Main.py.

💡 * Token : Remember the previous step we made a token for your bot. * 💡 ❗ Keep your token secure and private. This token grants access for complete control of your discord account.

Codes

Snippet

# -*- coding:utf-8 -*-

import discord
import asyncio

token = ""
client = discord.Client()

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.online, activity=discord.Game("Hello!"))
    print("Bot is running")
    print(client.user.name)
    print(client.user.id)

@client.event
async def on_message(message):
    if message.author.bot:
        return None

    if message.content == "!MakingBot":
        await message.channel.send("What's up?")


client.run(token)

Step 2. As shown in the figure, click the "Run" button to run it.

RunCodes

Step 3. On the Discord server that invited the bot, type "!MakingBot" into the chat window to see how the bot works.

CheckBotRunning

Conclusion

In this part, we implemented a Discord bot that works with simple programming.

Now, you know that making a bot is not too difficult.

With this knowledge, we hope that you're willing to expand on what you've learnt to create a better bot to manage your server more conveniently. 😁

Note

If you need more information to creating your own bot, visit the link below.

https://discordpy.readthedocs.io/en/stable/api.html#